﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Bas;
using nERP.Model;

namespace nERP.ViewModel.Bas.CustomerVMs
{
    public partial class CustomerListVM : BasePagedListVM<Customer_View, CustomerSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Customer_View>> InitGridHeader()
        {
            return new List<GridColumn<Customer_View>>{
                
                this.MakeGridHeader(x => x.Customer_CustomerCode).SetTitle(@Localizer["Page.客户编码"].Value),
                this.MakeGridHeader(x => x.Customer_CustomerName).SetTitle(@Localizer["Page.客户名称"].Value),
                this.MakeGridHeader(x => x.Customer_ContactPerson).SetTitle(@Localizer["Page.联系人"].Value),
                this.MakeGridHeader(x => x.Customer_PhoneNumber).SetTitle(@Localizer["Page.手机号码"].Value),
                this.MakeGridHeader(x => x.Customer_Email).SetTitle(@Localizer["_Admin.Email"].Value),
                this.MakeGridHeader(x => x.Customer_Faxing).SetTitle(@Localizer["Page.传真"].Value),
                this.MakeGridHeader(x => x.Customer_BeginCollect).SetTitle(@Localizer["Page.期初应收"].Value),
                this.MakeGridHeader(x => x.Customer_EndCollect).SetTitle(@Localizer["Page.期末应收"].Value),
                this.MakeGridHeader(x => x.Customer_TaxtRate).SetTitle(@Localizer["Page.税率"].Value),
                this.MakeGridHeader(x => x.Customer_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.Customer_Address).SetTitle(@Localizer["_Admin.Address"].Value),
                this.MakeGridHeader(x => x.Customer_Bank).SetTitle(@Localizer["Page.开户行"].Value),
                this.MakeGridHeader(x => x.Customer_TaxpayerNumber).SetTitle(@Localizer["Page.纳税人识别号"].Value),
                this.MakeGridHeader(x => x.Customer_BankAccount).SetTitle(@Localizer["Page.银行账号"].Value),
                this.MakeGridHeader(x => x.Customer_LandlinePhone).SetTitle(@Localizer["Page.固定电话"].Value),
                this.MakeGridHeader(x => x.Customer_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.Customer_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.Customer_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.Customer_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.Customer_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Customer_View> GetSearchQuery()
        {
            var query = DC.Set<Customer>()
                
                .CheckContain(Searcher.CustomerCode, x=>x.CustomerCode)
                .CheckContain(Searcher.CustomerName, x=>x.CustomerName)
                .CheckContain(Searcher.ContactPerson, x=>x.ContactPerson)
                .CheckEqual(Searcher.PhoneNumber, x=>x.PhoneNumber)
                .CheckContain(Searcher.Email, x=>x.Email)
                .CheckContain(Searcher.Faxing, x=>x.Faxing)
                .CheckEqual(Searcher.BeginCollect, x=>x.BeginCollect)
                .CheckEqual(Searcher.EndCollect, x=>x.EndCollect)
                .CheckEqual(Searcher.TaxtRate, x=>x.TaxtRate)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckContain(Searcher.Address, x=>x.Address)
                .CheckContain(Searcher.Bank, x=>x.Bank)
                .CheckContain(Searcher.TaxpayerNumber, x=>x.TaxpayerNumber)
                .CheckContain(Searcher.BankAccount, x=>x.BankAccount)
                .CheckContain(Searcher.LandlinePhone, x=>x.LandlinePhone)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new Customer_View
                {
				    ID = x.ID,
                    
                    Customer_CustomerCode = x.CustomerCode,
                    Customer_CustomerName = x.CustomerName,
                    Customer_ContactPerson = x.ContactPerson,
                    Customer_PhoneNumber = x.PhoneNumber,
                    Customer_Email = x.Email,
                    Customer_Faxing = x.Faxing,
                    Customer_BeginCollect = x.BeginCollect,
                    Customer_EndCollect = x.EndCollect,
                    Customer_TaxtRate = x.TaxtRate,
                    Customer_Remark = x.Remark,
                    Customer_Address = x.Address,
                    Customer_Bank = x.Bank,
                    Customer_TaxpayerNumber = x.TaxpayerNumber,
                    Customer_BankAccount = x.BankAccount,
                    Customer_LandlinePhone = x.LandlinePhone,
                    Customer_CreateTime = x.CreateTime,
                    Customer_UpdateTime = x.UpdateTime,
                    Customer_CreateBy = x.CreateBy,
                    Customer_UpdateBy = x.UpdateBy,
                    Customer_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Customer_View: Customer
    {
        
        public string Customer_CustomerCode { get; set; }
        public string Customer_CustomerName { get; set; }
        public string Customer_ContactPerson { get; set; }
        public string Customer_PhoneNumber { get; set; }
        public string Customer_Email { get; set; }
        public string Customer_Faxing { get; set; }
        public decimal? Customer_BeginCollect { get; set; }
        public decimal? Customer_EndCollect { get; set; }
        public decimal? Customer_TaxtRate { get; set; }
        public string Customer_Remark { get; set; }
        public string Customer_Address { get; set; }
        public string Customer_Bank { get; set; }
        public string Customer_TaxpayerNumber { get; set; }
        public string Customer_BankAccount { get; set; }
        public string Customer_LandlinePhone { get; set; }
        public DateTime? Customer_CreateTime { get; set; }
        public DateTime? Customer_UpdateTime { get; set; }
        public string Customer_CreateBy { get; set; }
        public string Customer_UpdateBy { get; set; }
        public bool Customer_IsValid { get; set; }

    }

}